<%@page import="org.springframework.web.servlet.mvc.support.RedirectAttributes"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>管理考试题</title>
		<!-- 前端校验提示信息颜色 -->
		<style>
			.error{ color:red}
		</style>
	</head>

	<body class="skin-2">
			<div class="main-content">
				<!-- #section:basics/content.breadcrumbs -->
				<div class="breadcrumbs" id="breadcrumbs">
					<script type="text/javascript">
						try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
					</script>

					<ul class="breadcrumb">
						<li>
							<i class="ace-icon fa fa-home home-icon"></i>
							<a href="tests">管理考试题</a>
						</li>
					</ul><!-- /.breadcrumb -->

					<!-- #section:basics/content.searchbox -->
					<div class="nav-search" id="nav-search">
						<form class="form-search">
							<span class="input-icon">
								<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
								<i class="ace-icon fa fa-search nav-search-icon"></i>
							</span>
						</form>
					</div><!-- /.nav-search -->

					<!-- /section:basics/content.searchbox -->
				</div>

				<!-- /section:basics/content.breadcrumbs -->
				<div class="page-content">
					<!-- #section:settings.box -->
					<div class="ace-settings-container" id="ace-settings-container">
						<div class="btn btn-app btn-xs btn-warning ace-settings-btn" id="ace-settings-btn">
							<i class="ace-icon fa fa-cog bigger-150"></i>
						</div>

						<div class="ace-settings-box clearfix" id="ace-settings-box">
							<div class="pull-left width-50">
								<!-- #section:settings.skins -->
								<div class="ace-settings-item">
									<div class="pull-left">
										<select id="skin-colorpicker" class="hide">
											<option data-skin="no-skin" value="#438EB9">#438EB9</option>
											<option data-skin="skin-1" value="#222A2D">#222A2D</option>
											<option data-skin="skin-2" value="#C6487E">#C6487E</option>
											<option data-skin="skin-3" value="#D0D0D0">#D0D0D0</option>
										</select>
									</div>
									<span>&nbsp; Choose Skin</span>
								</div>

								<!-- /section:settings.skins -->

								<!-- #section:settings.navbar -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-navbar">
									<label class="lbl" for="ace-settings-navbar"> Fixed Navbar</label>
								</div>

								<!-- /section:settings.navbar -->

								<!-- #section:settings.sidebar -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-sidebar">
									<label class="lbl" for="ace-settings-sidebar"> Fixed Sidebar</label>
								</div>

								<!-- /section:settings.sidebar -->

								<!-- #section:settings.breadcrumbs -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-breadcrumbs">
									<label class="lbl" for="ace-settings-breadcrumbs"> Fixed Breadcrumbs</label>
								</div>

								<!-- /section:settings.breadcrumbs -->

								<!-- #section:settings.rtl -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-rtl">
									<label class="lbl" for="ace-settings-rtl"> Right To Left (rtl)</label>
								</div>

								<!-- /section:settings.rtl -->

								<!-- #section:settings.container -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-add-container">
									<label class="lbl" for="ace-settings-add-container">
										Inside
										<b>.container</b>
									</label>
								</div>

								<!-- /section:settings.container -->
							</div><!-- /.pull-left -->

							<div class="pull-left width-50">
								<!-- #section:basics/sidebar.options -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-hover">
									<label class="lbl" for="ace-settings-hover"> Submenu on Hover</label>
								</div>

								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-compact">
									<label class="lbl" for="ace-settings-compact"> Compact Sidebar</label>
								</div>

								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-highlight">
									<label class="lbl" for="ace-settings-highlight"> Alt. Active Item</label>
								</div>

								<!-- /section:basics/sidebar.options -->
							</div><!-- /.pull-left -->
						</div><!-- /.ace-settings-box -->
					</div>
					<!-- /.ace-settings-container -->
					<!-- /section:settings.box -->
					
					<!-- /section:settings.box -->
					<div class="page-content-area">
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div class="row">
									<div class="col-xs-12 table-responsive">
										<button id="addTest" class="btn btn-primary">
											<i class="ace-icon fa fa-plus align-top bigger-125"></i>
											添加考试题
										</button>
										<table id="sample-table-1" class="table table-condensed table-bordered table-hover">
											<thead>
												<tr>
													<th class="center">
														<label class="position-relative">
															<input type="checkbox" class="ace" />
															<span class="lbl"></span>
														</label>
													</th>
													<th>题号</th>
													<th>科目</th>
													<th>提干</th>
													<th>选项A</th>
													<th>选项B</th>
													<th>选项C</th>
													<th>选项D</th>
													<th>答案</th>
													<th>题目类型</th>
													<th>题目分数</th>
													<th>操作</th>
												</tr>
											</thead>

											<tbody>
												<c:forEach items="${examTestList.dates}" var="examTest">
													<tr>
														<td class="center">
															<label class="position-relative">
																<input type="checkbox" class="ace" />
																<span class="lbl"></span>
															</label>
														</td>
														<td>${examTest.id}</td>
														<td>${examTest.subject.name}</td>
														<td>${examTest.content}</td>
														<td>${examTest.chooseA}</td>
														<td>${examTest.chooseB}</td>
														<td>${examTest.chooseC}</td>
														<td>${examTest.chooseD}</td>
														<td>${examTest.answer}</td>
														<td>${examTest.examTestType.testType}</td>
														<td>${examTest.examTestType.testTypeScore}</td>
														<td>
															<a class="btn btn-xs btn-primary show-test" data-toggle="tooltip" title="查看试题信息">
																<i class="ace-icon fa fa-comment"></i>
															</a>
															<a class="btn btn-xs btn-primary edit-test" data-toggle="tooltip" title="修改试题">
																<i class="ace-icon fa fa-pencil"></i>
															</a>
															<a class="btn btn-xs btn-primary delete-test" data-toggle="tooltip" title="删除试题">
																<i class="ace-icon fa fa-trash-o"></i>
															</a>
														</td>
													</tr>
												</c:forEach>
												<tr>
													<td colspan="12">
														<jsp:include page="../page/page.jsp">
															<jsp:param name="url" value="tests"/>
															<jsp:param name="items" value="${examTestList.totalSize}"/>
														</jsp:include>
													</td>
												</tr>
											</tbody>
										</table>
										
										<!-- 添加试题模态框 -->
										<div id="addTestModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
											<div class="modal-dialog">
												<div class="modal-content">
												  <div class="modal-header">
												    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
												    <h3 id="myModalLabel" style="color:#999">添加考试题</h3>
												  </div>
												  <div class="modal-body">
												    <form id="addTestForm" method="post" class="form-horizontal">
												    	<div class="form-group">
												    		<label for="subject_name" class="col-sm-3 control-label"><i style="color:red">* </i><b>科目:</b></label>
												    		<div class="col-sm-4">
												    			<select class="form-control" name="subject_name" id="subject_name"></select>
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="examTestType_testType" class="col-sm-3 control-label"><i style="color:red">* </i><b>试题类型:</b></label>
												    		<div class="col-sm-3">
												    			<select class="form-control" name="examTestType_testType" id="examTestType_testType"></select>
												    		</div>
												    		<label id="testTypeText" class="col-sm-2.5 control-label"></label>
												    	</div>
												    	<div class="form-group">
												    		<label for="content" class="col-sm-3 control-label"><i style="color:red">* </i><b>题干:</b></label>
												    		<div class="col-sm-8">
												    			<textarea class="form-control" name="content" id="content" rows="7" placeholder="填写题目内容"></textarea>
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="chooseA" class="col-sm-3 control-label"><i style="color:red">* </i><b>选项A:</b></label>
												    		<div class="col-sm-8">
												    			<input class="form-control" type="text" name="chooseA" id="chooseA" placeholder="填写候选答案内容,作为选项A">
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="chooseB" class="col-sm-3 control-label"><i style="color:red">* </i><b>选项B:</b></label>
												    		<div class="col-sm-8">
												    			<input class="form-control" type="text" name="chooseB" id="chooseB" placeholder="填写候选答案内容,作为选项B">
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="chooseC" class="col-sm-3 control-label"><i style="color:red">* </i><b>选项C:</b></label>
												    		<div class="col-sm-8">
												    			<input class="form-control" type="text" name="chooseC" id="chooseC" placeholder="填写候选答案内容,作为选项C">
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="chooseD" class="col-sm-3 control-label"><i style="color:red">* </i><b>选项D:</b></label>
												    		<div class="col-sm-8">
												    			<input class="form-control" type="text" name="chooseD" id="chooseD" placeholder="填写候选答案内容,作为选项D">
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for='answer' class="col-sm-3 control-label"><i style="color:red">* </i><b>答案: </b></label>
													    	<div class="col-sm-offset-0 col-sm-8">
													    		<div id="answer">
													    			
													    		</div>
													    	</div>
												    	</div>
												    	<div class="modal-footer">
													    	<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
													    	<button class="btn btn-primary" id="addTestbtn">确定提交</button>
													  </div>
												    </form>
												  </div>
												  
												</div>
											</div>
										</div><!-- addTestModal end -->
										<!-- 查看试题信息模态框 -->
										<div id="showTestModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
											<div class="modal-dialog">
												<div class="modal-content">
												  <div class="modal-header">
												    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
												    <h3 id="myModalLabel">查看详细试题</h3>
												  </div>
												  <div class="modal-body">
												    <div><label style="display:inline-block;margin-right:10px;">试题科目:</label><p style="display:inline-block;color:#999;"></p></div>
												    <div><label style="display:inline-block;margin-right:10px;">题目:</label><p style="display:inline-block;color:#999;"></p></div>
												    <div><label style="display:inline-block;margin-right:10px;">A:</label><p style="display:inline-block;color:#999;"></p></div>
												    <div><label style="display:inline-block;margin-right:10px;">B:</label><p style="display:inline-block;color:#999;"></p></div>
												    <div><label style="display:inline-block;margin-right:10px;">C:</label><p style="display:inline-block;color:#999;"></p></div>
												    <div><label style="display:inline-block;margin-right:10px;">D:</label><p style="display:inline-block;color:#999;"></p></div>
												    <div><label style="display:inline-block;margin-right:10px;">答案:</label><p style="display:inline-block;color:#999;"></p></div>
												  </div>
												  <div class="modal-footer">
												    <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
												  </div>
												</div>
											</div>
										</div><!-- showTestModal end -->
										<!-- 修改试题信息模态框 -->
										<div id="editTestModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
											<div class="modal-dialog">
												<div class="modal-content">
												  <div class="modal-header">
												    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
												    <h3 id="myModalLabel" style="color:#999">修改考试题</h3>
												  </div>
												  <div class="modal-body">
												    <form id="editTestForm" method="post" class="form-horizontal">
												    	<input type="hidden" id="examTestId" value="" />
												    	<div class="form-group">
												    		<label for="subject_name" class="col-sm-3 control-label"><i style="color:red">* </i><b>科目:</b></label>
												    		<div class="col-sm-4">
												    			<select class="form-control" name="subject_name" id="subject_name"></select>
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="examTestType_testType" class="col-sm-3 control-label"><i style="color:red">* </i><b>试题类型:</b></label>
												    		<div class="col-sm-3">
												    			<select class="form-control" name="examTestType_testType" id="examTestType_testType"></select>
												    		</div>
												    		<label id="testTypeText" class="col-sm-2.5 control-label"></label>
												    	</div>
												    	<div class="form-group">
												    		<label for="content" class="col-sm-3 control-label"><i style="color:red">* </i><b>题干:</b></label>
												    		<div class="col-sm-8">
												    			<textarea class="form-control" name="content" id="content" rows="7"></textarea>
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="chooseA" class="col-sm-3 control-label"><i style="color:red">* </i><b>选项A:</b></label>
												    		<div class="col-sm-8">
												    			<input class="form-control" type="text" name="chooseA" id="chooseA">
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="chooseB" class="col-sm-3 control-label"><i style="color:red">* </i><b>选项B:</b></label>
												    		<div class="col-sm-8">
												    			<input class="form-control" type="text" name="chooseB" id="chooseB">
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="chooseC" class="col-sm-3 control-label"><i style="color:red">* </i><b>选项C:</b></label>
												    		<div class="col-sm-8">
												    			<input class="form-control" type="text" name="chooseC" id="chooseC">
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for="chooseD" class="col-sm-3 control-label"><i style="color:red">* </i><b>选项D:</b></label>
												    		<div class="col-sm-8">
												    			<input class="form-control" type="text" name="chooseD" id="chooseD">
												    		</div>
												    	</div>
												    	<div class="form-group">
												    		<label for='answer' class="col-sm-3 control-label"><i style="color:red">* </i><b>答案: </b></label>
													    	<div class="col-sm-offset-0 col-sm-8">
													    		<div id="answer">
													    			
													    		</div>
													    	</div>
												    	</div>
												    	<div class="modal-footer">
													    	<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
													    	<button class="btn btn-primary" id="editTestbtn">确定修改</button>
													  </div>
												    </form>
												  </div>
												</div>
											</div>
										</div><!-- editTestModal end -->
										<!-- 删除试题信息模态框 -->
										<div id="deletdTestModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
											<div class="modal-dialog">
												<div class="modal-content">
												  <div class="modal-header">
												    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
												    <h3 id="myModalLabel">删除试题</h3>
												  </div>
												  <div class="modal-body">
												    <h4>确定删除该试题？</h4>
												    <input type="hidden" id="examTestId" value=""></input>
												  </div>
												  <div class="modal-footer">
												    <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
												    <button class="btn btn-primary" id="deleteTestbtn">确定删除</button>
												  </div>
												</div>
											</div>
										</div><!-- deletdTestModal end -->
									</div><!-- /.span -->
								</div><!-- /.row -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content-area -->
				</div><!-- /.page-content -->
			</div><!-- /.main-content -->

		<!-- basic scripts -->

		<!--[if !IE]> -->
		<script type="text/javascript">
			window.jQuery || document.write("<script src='${pageContext.request.contextPath}/static/assets/js/jquery.min.js'>"+"<"+"/script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='../assets/js/jquery1x.min.js'>"+"<"+"/script>");
</script>
<![endif]-->
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) document.write("<script src='${pageContext.request.contextPath}/static/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="${pageContext.request.contextPath}/static/assets/js/bootstrap.min.js"></script>

		<!-- page specific plugin scripts -->
		<script src="${pageContext.request.contextPath}/static/assets/js/jquery.dataTables.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/jquery.dataTables.bootstrap.js"></script>

		<!-- ace scripts -->
		<script src="${pageContext.request.contextPath}/static/assets/js/ace-elements.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/ace.min.js"></script>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
		
			//用ajax获取科目名和试题类型,向模态框的select输出值
	  		$(document).ready(function(){
	  			$("#addTest").click(function(){
	  				//获取科目名
		  			$.ajax({
		  				type:"POST",
		  				url:"getSubjectName",
		  				dataType:"json",
		  				success:function(data){
		  					$("#addTestModal #addTestForm select[name='subject_name']").empty();
		  					for(var i in data){
		  						$("#addTestModal #addTestForm select[name='subject_name']").append("<option value=" + i + ">" + data[i] + "</option>");
		  					}
		  				}
		  			});
	  				
	  				//获取试题类型
		  			$.ajax({
		  				type:"POST",
		  				url:"getExamTestType",
		  				dataType:"json",
		  				success:function(data){
		  					$("#addTestModal #addTestForm select[name='examTestType_testType']").empty();
		  					for(var i in data){
		  						$("#addTestModal #addTestForm select[name='examTestType_testType']").append("<option value=" + i + ">" + data[i] + "</option>");
		  					}
		  					//根据判断添加单选按钮或复选框
		  					if("单选题" == data[1] || "单选" == data[1]){
			  					$("#addTestModal #addTestForm label[id='testTypeText']").html("<b>本题每题1分</b>");
			  					//清掉单选按钮
			  					$("#addTestModal #addTestForm div[id='answer']").empty();
			  					//添加单选按钮
			  					$("#addTestModal #addTestForm div[id='answer']").append("<label style='margin-right:10px'><input type='radio' name='answer' value='A' checked>选项A</label>" + 
			  							"<label style='margin-right:10px'><input type='radio' name='answer' value='B'>选项B</label><label style='margin-right:10px'><input type='radio' name='answer' value='C'>选项C</label>" + 
			  							"<label style='margin-right:10px'><input type='radio' name='answer' value='D'>选项D</label>");
			  				}else{
			  					//添加复选框
			  					$("#addTestModal #addTestForm label[id='testTypeText']").html("<b>本题每题2分</b>");
			  					$("#addTestModal #addTestForm div[id='answer']").empty();
			  					$("#addTestModal #addTestForm div[id='answer']").append("<label style='margin-right:10px'><input type='checkbox' name='answer' value='A'>选项A</label>" + 
			  							"<label style='margin-right:10px'><input type='checkbox' name='answer' value='B'>选项B</label><label style='margin-right:10px'><input type='checkbox' name='answer' value='C'>选项C</label>" + 
			  							"<label style='margin-right:10px'><input type='checkbox' name='answer' value='D'>选项D</label>");
			  				}
		  				}
		  			})
		  			$("#addTestModal").modal("show");
	  			});
	  			
	  			//根据选择试题类型给出不同分值并且替换答案单选按钮或复选框
	  			$("#addTestModal #addTestForm select[name='examTestType_testType']").change(function(){
	  				//获取select值（id号）再通过id获取option的文本
	  				var selectTestTypeValue = $("#addTestModal #addTestForm select[name='examTestType_testType']").val();
	  				var optionTestTypeText = $("#addTestModal #addTestForm select[name='examTestType_testType'] option[value='"+ selectTestTypeValue + "']").text();
	  				//根据判断添加单选按钮或复选框
	  				if("单选题" == optionTestTypeText || "单选" == optionTestTypeText){
	  					$("#addTestModal #addTestForm label[id='testTypeText']").html("<b>本题每题1分</b>");
	  					$("#addTestModal #addTestForm div[id='answer']").empty();
	  					$("#addTestModal #addTestForm div[id='answer']").append("<label style='margin-right:10px'><input type='radio' name='answer' value='A' checked>选项A</label>" + 
	  							"<label style='margin-right:10px'><input type='radio' name='answer' value='B'>选项B</label><label style='margin-right:10px'><input type='radio' name='answer' value='C'>选项C</label>" + 
	  							"<label style='margin-right:10px'><input type='radio' name='answer' value='D'>选项D</label>")
	  				}else{
	  					$("#addTestModal #addTestForm label[id='testTypeText']").html("<b>本题每题2分</b>");
	  					$("#addTestModal #addTestForm div[id='answer']").empty();
	  					$("#addTestModal #addTestForm div[id='answer']").append("<label style='margin-right:10px'><input type='checkbox' name='answer' value='A'>选项A</label>" + 
	  							"<label style='margin-right:10px'><input type='checkbox' name='answer' value='B'>选项B</label><label style='margin-right:10px'><input type='checkbox' name='answer' value='C'>选项C</label>" + 
	  							"<label style='margin-right:10px'><input type='checkbox' name='answer' value='D'>选项D</label>")
	  				}
	  				
	  			});
	  			
	  			//添加表单前端校验
	  			$("#addTestForm").validate({
	  				//定义规则
	  				rules:{
	  					subject_name:"required",
	  					examTestType_testType:"required",
	  					content:{
	  						required: true,
	  						minlength: 2,
	  					},
	  					chooseA:{
	  						required:true,
	  						minlength:2,
	  					},
	  					chooseB:{
	  						required:true,
	  						minlength:2,
	  					},
	  					chooseC:{
	  						required:true,
	  						minlength:2,
	  					},
	  					chooseD:{
	  						required:true,
	  						minlength:2,
	  					},
	  					answer:"required",
	  				},
	  				//定义提示信息
	  				messages:{
	  					subject_name:{
	  						required:"必填字段",
	  					},
	  					examTestType_testType:{
	  						required:"必填字段",
	  					},
	  					content:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					chooseA:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					chooseB:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					chooseC:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					chooseD:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					answer:{
	  						required:"必填字段",
	  					}
	  				},
	  				
	  			});
	  			//修改表单前端校验
	  			$("#editTestForm").validate({
	  				//定义规则
	  				rules:{
	  					subject_name:"required",
	  					examTestType_testType:"required",
	  					content:{
	  						required: true,
	  						minlength: 2,
	  					},
	  					chooseA:{
	  						required:true,
	  						minlength:2,
	  					},
	  					chooseB:{
	  						required:true,
	  						minlength:2,
	  					},
	  					chooseC:{
	  						required:true,
	  						minlength:2,
	  					},
	  					chooseD:{
	  						required:true,
	  						minlength:2,
	  					},
	  					answer:"required",
	  				},
	  				//定义提示信息
	  				messages:{
	  					subject_name:{
	  						required:"必填字段",
	  					},
	  					examTestType_testType:{
	  						required:"必填字段",
	  					},
	  					content:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					chooseA:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					chooseB:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					chooseC:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					chooseD:{
	  						required:"必填字段",
		  					minlength:"内容长度不符合，必须两个字符或以上",
	  					},
	  					answer:{
	  						required:"必填字段",
	  					}
	  				},
	  				
	  			});
	  			//点击添加按钮
	  			$("#addTestbtn").click(function(){
	  				var subId = $("#addTestForm select[name='subject_name']").val();
	  				var testTypeId = $("#addTestForm select[name='examTestType_testType']").val();
	  				var content = $("#addTestForm textarea[name='content']").val();
	  				var chooseA = $("#addTestForm input[name='chooseA']").val();
	  				var chooseB = $("#addTestForm input[name='chooseB']").val();
	  				var chooseC = $("#addTestForm input[name='chooseC']").val();
	  				var chooseD = $("#addTestForm input[name='chooseD']").val();
	  				var answer = "";
	  				//判断是答案是单选还是多选并获取值
	  				var testTypeText = $("#addTestForm select[name='examTestType_testType'] option[value=" + testTypeId +"]").text();
	  				if("单选题" == testTypeText || "单选" == testTypeText){
	  					answer += $("#addTestForm input[name='answer']:checked").val();
	  				}else{
	  					//遍历被选中的复选框
	  					var checkbox = $("#addTestForm input[name='answer']:checked");
	  					checkbox.each(function(){
	  						answer += $(this).val();
	  					})
	  				}
	  				//判断字段有没有空的
	  				if(subId != "" && testTypeId != "" && content != "" && chooseA != "" && chooseB != "" 
	  						&& chooseC != "" && chooseD != "" && answer != ""){
	  					$.ajax({
	  						type:"POST",
	  						url:"addExamTest",
	  						dataType:"json",
	  						data:{
	  							"subId": subId,
	  							"testTypeId": testTypeId,
	  							"content": content,
	  							"chooseA": chooseA,
	  							"chooseB": chooseB,
	  							"chooseC": chooseC,
	  							"chooseD": chooseD,
	  							"answer": answer
	  						},
	  						success:function(data){
	  							if("f" == data){
	  								alert("填写的信息有误,添加失败");
	  								$("#addTestModal").modal("show");
	  							}else{
	  								alert("添加成功");
	  								window.location.reload();
	  							}
	  							
	  						}
	  					})
	  				}
	  				//console.log(subId + " " + testTypeId + " " + content + " " + chooseA + " " + chooseB + " " + chooseC + " " + chooseD + " " + answer);
	  				
	  			})
	  			
	  			//查看试题信息
	  			$(".show-test").click(function(){
	  				var testId = $(this).parent().siblings().eq(1).text();
	  				$.ajax({
	  					type:"POST",
	  					url:"findTestById",
	  					data:{
	  						"id":testId
	  					},
	  					dataType:"json",
	  					success:function(data){
	  						$("#showTestModal .modal-body div:first-child p").html(data.subjectName + "  <span style='color:#000;'>----(" + data.testType + "每题"+ data.testTypeScore + "分。)</span>");
	  						$("#showTestModal .modal-body div:nth-child(2) p").text(data.content);
	  						$("#showTestModal .modal-body div:nth-child(3) p").text(data.chooseA);
	  						$("#showTestModal .modal-body div:nth-child(4) p").text(data.chooseB);
	  						$("#showTestModal .modal-body div:nth-child(5) p").text(data.chooseC);
	  						$("#showTestModal .modal-body div:nth-child(6) p").text(data.chooseD);
	  						$("#showTestModal .modal-body div:last-child p").text(data.answer);
	  		  				$("#showTestModal").modal("show");
	  					}
	  				})
	  				
	  			})
	  			//修改试题
	  			$(".edit-test").click(function(){
	  				//根据id查询试题
	  				var testId = $(this).parent().siblings().eq(1).text();
	  				var examTestId = "";
	  				var subjectName = "";
	  				var testType = "";
	  				var content = "";
	  				var chooseA = "";
	  				var chooseB = "";
	  				var chooseC = "";
	  				var chooseD = "";
	  				var answer = "";
	  				$.ajax({
	  					type:"POST",
	  					url:"findTestById",
	  					dataType:"json",
	  					data:{
	  						"id": testId
	  					},
	  					success:function(data){
	  						examTestId = data.examTestId;
	  						subjectName = data.subjectName;
	  						testType = data.testType;
	  						content = data.content;
	  						chooseA = data.chooseA;
	  						chooseB = data.chooseB;
	  						chooseC = data.chooseC;
	  						chooseD = data.chooseD;
	  						answer = data.answer;
	  						//设置隐藏域id
	  						$("#editTestModal #editTestForm #examTestId").val(examTestId);
	  						//console.log(subjectName + " " +testType + " " + content + " " + chooseA + " " + chooseB + " " + chooseC + " " + chooseD + " " + answer);
	  		  				//查询科目名
			  				$.ajax({
			  					type:"POST",
			  					url:"getSubjectName",
			  					dataType:"json",
			  					success:function(data){
			  						$("#editTestModal #editTestForm select[id='subject_name']").empty();
			  						for(var i in data){
			  							$("#editTestModal #editTestForm select[id='subject_name']").append("<option value='" + i + "'>" + data[i] + "</option>");
			  							if(subjectName == data[i]){
			  								$("#editTestModal #editTestForm select[id='subject_name'] option[value='" + i + "']").attr("selected", "true");
			  							}
			  						}
			  					}
			  				})
			  				//查询试题类型
			  				$.ajax({
			  					type:"POST",
			  					url:"getExamTestType",
			  					dataType:"json",
			  					success:function(data){
			  						$("#editTestModal #editTestForm select[id='examTestType_testType']").empty();
			  						for(var i in data){
			  							$("#editTestModal #editTestForm select[id='examTestType_testType']").append("<option value='" + i + "'>" + data[i] + "</option>");
			  							if(testType == data[i]){
			  								$("#editTestModal #editTestForm select[id='examTestType_testType'] option[value='" + i + "']").attr("selected", "true");
			  							}
			  						}
			  						$("#editTestModal #editTestForm textarea[id='content']").val(content);
			  						$("#editTestModal #editTestForm input[id='chooseA']").val(chooseA);
			  						$("#editTestModal #editTestForm input[id='chooseB']").val(chooseB);
			  						$("#editTestModal #editTestForm input[id='chooseC']").val(chooseC);
			  						$("#editTestModal #editTestForm input[id='chooseD']").val(chooseD);
			  						if(testType == "单选题" || testType == "单选"){
			  							$("#editTestModal #editTestForm label[id='testTypeText']").html("<b>本题每题1分</b>");
					  					//清掉单选按钮
					  					$("#editTestModal #editTestForm div[id='answer']").empty();
					  					//添加单选按钮
			  							$("#editTestModal #editTestForm div[id='answer']").append("<label style='margin-right:10px'><input type='radio' name='answer' value='A'>选项A</label>" + 
			  							"<label style='margin-right:10px'><input type='radio' name='answer' value='B'>选项B</label><label style='margin-right:10px'><input type='radio' name='answer' value='C'>选项C</label>" + 
			  							"<label style='margin-right:10px'><input type='radio' name='answer' value='D'>选项D</label>");
			  							$("#editTestModal #editTestForm div[id='answer'] input[value='" + answer + "']").attr("checked", "true");
			  						}else{
			  							//添加复选框
					  					$("#editTestModal #editTestForm label[id='testTypeText']").html("<b>本题每题2分</b>");
					  					$("#editTestModal #editTestForm div[id='answer']").empty();
					  					$("#editTestModal #editTestForm div[id='answer']").append("<label style='margin-right:10px'><input type='checkbox' name='answer' value='A'>选项A</label>" + 
					  							"<label style='margin-right:10px'><input type='checkbox' name='answer' value='B'>选项B</label><label style='margin-right:10px'><input type='checkbox' name='answer' value='C'>选项C</label>" + 
					  							"<label style='margin-right:10px'><input type='checkbox' name='answer' value='D'>选项D</label>");
					  					$("#editTestModal #editTestForm div[id='answer'] input[value='" + answer.charAt(0) + "']").attr("checked", "true");
					  					$("#editTestModal #editTestForm div[id='answer'] input[value='" + answer.charAt(1) + "']").attr("checked", "true");
					  					$("#editTestModal #editTestForm div[id='answer'] input[value='" + answer.charAt(2) + "']").attr("checked", "true");
					  					$("#editTestModal #editTestForm div[id='answer'] input[value='" + answer.charAt(3) + "']").attr("checked", "true");
					  					$("#editTestModal #editTestForm div[id='answer'] input[value='" + answer.charAt(4) + "']").attr("checked", "true");
					  					$("#editTestModal #editTestForm div[id='answer'] input[value='" + answer.charAt(5) + "']").attr("checked", "true");
					  					$("#editTestModal #editTestForm div[id='answer'] input[value='" + answer.charAt(6) + "']").attr("checked", "true");
			  						}
			  						$("#editTestModal").modal("show");
			  					}
			  				})
	  					}
	  				});
	  			})
	  			//根据选择试题类型给出不同分值并且替换答案单选按钮或复选框
	  			$("#editTestModal #editTestForm select[name='examTestType_testType']").change(function(){
	  				//获取select值（id号）再通过id获取option的文本
	  				var selectTestTypeValue = $("#editTestModal #editTestForm select[name='examTestType_testType']").val();
	  				var optionTestTypeText = $("#editTestModal #editTestForm select[name='examTestType_testType'] option[value='"+ selectTestTypeValue + "']").text();
	  				//根据判断添加单选按钮或复选框
	  				if("单选题" == optionTestTypeText || "单选" == optionTestTypeText){
	  					$("#editTestModal #editTestForm label[id='testTypeText']").html("<b>本题每题1分</b>");
	  					//清掉单选按钮
	  					$("#editTestModal #editTestForm div[id='answer']").empty();
	  					//添加单选按钮
						$("#editTestModal #editTestForm div[id='answer']").append("<label style='margin-right:10px'><input type='radio' name='answer' value='A' checked>选项A</label>" + 
							"<label style='margin-right:10px'><input type='radio' name='answer' value='B'>选项B</label><label style='margin-right:10px'><input type='radio' name='answer' value='C'>选项C</label>" + 
							"<label style='margin-right:10px'><input type='radio' name='answer' value='D'>选项D</label>");
					}else{
	  					$("#addTestModal #addTestForm label[id='testTypeText']").html("<b>本题每题2分</b>");
	  					$("#addTestModal #addTestForm div[id='answer']").empty();
	  					//添加复选框
	  					$("#editTestModal #editTestForm label[id='testTypeText']").html("<b>本题每题2分</b>");
	  					$("#editTestModal #editTestForm div[id='answer']").empty();
	  					$("#editTestModal #editTestForm div[id='answer']").append("<label style='margin-right:10px'><input type='checkbox' name='answer' value='A'>选项A</label>" + 
	  							"<label style='margin-right:10px'><input type='checkbox' name='answer' value='B'>选项B</label><label style='margin-right:10px'><input type='checkbox' name='answer' value='C'>选项C</label>" + 
	  							"<label style='margin-right:10px'><input type='checkbox' name='answer' value='D'>选项D</label>");
	  				}
	  				
	  			});
	  			//点击确认修改按钮
	  			$("#editTestbtn").click(function(){
	  				var id = $("#editTestForm #examTestId").val();
	  				var subId = $("#editTestForm select[name='subject_name']").val();
	  				var testTypeId = $("#editTestForm select[name='examTestType_testType']").val();
	  				var content = $("#editTestForm textarea[name='content']").val();
	  				var chooseA = $("#editTestForm input[name='chooseA']").val();
	  				var chooseB = $("#editTestForm input[name='chooseB']").val();
	  				var chooseC = $("#editTestForm input[name='chooseC']").val();
	  				var chooseD = $("#editTestForm input[name='chooseD']").val();
	  				var answer = "";
	  				//判断是答案是单选还是多选并获取值
	  				var testTypeText = $("#editTestForm select[name='examTestType_testType'] option[value=" + testTypeId +"]").text();
	  				if("单选题" == testTypeText || "单选" == testTypeText){
	  					answer += $("#editTestForm input[name='answer']:checked").val();
	  				}else{
	  					//遍历被选中的复选框
	  					var checkbox = $("#editTestForm input[name='answer']:checked");
	  					checkbox.each(function(){
	  						answer += $(this).val();
	  					})
	  				}
	  				//判断字段有没有空的
	  				if(subId != "" && testTypeId != "" && content != "" && chooseA != "" && chooseB != "" 
	  						&& chooseC != "" && chooseD != "" && answer != ""){
	  					$.ajax({
	  						type:"POST",
	  						url:"editExamTest",
	  						dataType:"json",
	  						data:{
	  							"id": id,
	  							"subId": subId,
	  							"testTypeId": testTypeId,
	  							"content": content,
	  							"chooseA": chooseA,
	  							"chooseB": chooseB,
	  							"chooseC": chooseC,
	  							"chooseD": chooseD,
	  							"answer": answer
	  						},
	  						success:function(data){
	  							if("f" == data){
	  								alert("填写的信息有误,修改失败");
	  								$("#editTestModal").modal("show");
	  							}else{
	  								alert("修改成功");
	  								window.location.reload();
	  							}
	  							
	  						}
	  					})
	  				}
	  				//console.log(subId + " " + testTypeId + " " + content + " " + chooseA + " " + chooseB + " " + chooseC + " " + chooseD + " " + answer);
	  				
	  			});
	  			$(".delete-test").click(function(){
	  				var examTestId = $(this).parent().siblings().eq(1).text();
	  				$("#deletdTestModal #examTestId").val(examTestId);
	  				$("#deletdTestModal").modal("show");
	  			});
	  			$("#deletdTestModal #deleteTestbtn").click(function(){
	  				$("#deletdTestModal").modal("hide");
	  				var examTestId = $("#deletdTestModal input[id='examTestId']").val();
	  				location.href = "deleteExamTest/" + examTestId;
	  			});
	  			if("${message}"){
	  				alert("${message}");
	  			}
	  		})
	  	
			jQuery(function($) {
				var oTable1 = 
				$('#sample-table-2')
				//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
				.dataTable( {
					bAutoWidth: false,
					"aoColumns": [
					  { "bSortable": false },
					  null, null,null, null, null,
					  { "bSortable": false }
					],
					"aaSorting": [],
			
					//,
					//"sScrollY": "200px",
					//"bPaginate": false,
			
					//"sScrollX": "100%",
					//"sScrollXInner": "120%",
					//"bScrollCollapse": true,
					//Note: if you are applying horizontal scrolling (sScrollX) on a ".table-bordered"
					//you may want to wrap the table inside a "div.dataTables_borderWrap" element
			
					//"iDisplayLength": 50
			    } );
				/**
				var tableTools = new $.fn.dataTable.TableTools( oTable1, {
					"sSwfPath": "../../copy_csv_xls_pdf.swf",
			        "buttons": [
			            "copy",
			            "csv",
			            "xls",
						"pdf",
			            "print"
			        ]
			    } );
			    $( tableTools.fnContainer() ).insertBefore('#sample-table-2');
				*/
			
			
				$(document).on('click', 'th input:checkbox' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
				});
			
			
				$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
				function tooltip_placement(context, source) {
					var $source = $(source);
					var $parent = $source.closest('table')
					var off1 = $parent.offset();
					var w1 = $parent.width();
			
					var off2 = $source.offset();
					//var w2 = $source.width();
			
					if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
					return 'left';
				}
			
			});
			$(function () {
			  $('[data-toggle="tooltip"]').tooltip()
			});
			
			
		</script>

		<!-- the following scripts are used in demo only for onpage help and you don't need them -->
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace.onpage-help.css" />
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/docs/assets/js/themes/sunburst.css">

		<script type="text/javascript"> ace.vars['base'] = '..'; </script>
		<script src="${pageContext.request.contextPath}/static/assets/js/ace/elements.onpage-help.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/ace/ace.onpage-help.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/rainbow.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/generic.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/html.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/css.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/javascript.js"></script>
	</body>
</html>




